﻿using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;

namespace _11Net8AspNetCore_WebApis.Filter
{
    public class LoggerMyActionFilter : IActionFilter
    {

        private ILogger<LoggerMyActionFilter> _Logger = null;
        public LoggerMyActionFilter(ILogger<LoggerMyActionFilter> logger)
        {
            _Logger = logger;
        }

        public void OnActionExecuted(ActionExecutedContext context)
        {
            Console.WriteLine("执行后");
            _Logger.LogInformation("日志执行后");
        }

        /// <summary>
        /// Action 执行之前调佣
        /// </summary>
        /// <param name="context"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void OnActionExecuting(ActionExecutingContext context)
        {
            Console.WriteLine("执行前");
            _Logger.LogInformation("日志执行前");
        }
    }
}
